# -*- coding = utf-8 -*-
# @Time    : 2025/3/28 下午7:23
# @Author  : yqk
# @File    : study_bs42.py
# @Software: PyCharm

from bs4 import BeautifulSoup

html ='''
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BeautifulSoup 学习示例 - 表格</title>
</head>
<body>

  <header>
    <h1>欢迎来到 BeautifulSoup 爬虫教程</h1>
  </header>

  <section>
    <h2>学生成绩表</h2>
    <table border="1">
      <thead>
        <tr>
          <th>学号</th>
          <th>姓名</th>
          <th>语文</th>
          <th>数学</th>
          <th>英语</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>001</td>
          <td>张三</td>
          <td>85</td>
          <td>90</td>
          <td>88</td>
        </tr>
        <tr>
          <td>002</td>
          <td>李四</td>
          <td>78</td>
          <td>85</td>
          <td>80</td>
        </tr>
        <tr>
          <td>003</td>
          <td>王五</td>
          <td>92</td>
          <td>88</td>
          <td>94</td>
        </tr>
        <tr>
          <td>004</td>
          <td>赵六</td>
          <td>75</td>
          <td>80</td>
          <td>72</td>
        </tr>
      </tbody>
    </table>
  </section>

  <footer>
    <p>版权所有 &copy; 2025 学习爬虫</p>
  </footer>

</body>
</html>

'''
soup = BeautifulSoup(html, 'html.parser')
tr = soup.find('tr')
# print(tr)
#获取所有的tr标签
trs = soup.find_all('tr')
# for tr in trs:
#     print(tr)

#获取id = nr 的tr标签
# tr = soup.find('tr', id='nr')

# 将所有class =odd, align = center的tr标签找出来
# trs = soup.find_all('tr', class_='odd', align='center')

# 获取所有属性target='_blank' a标签的href属性
# a_tags = soup.find_all('a', target='_blank')
# for a_tag in a_tags:
#     print(a_tag['href'])

#css 选择器
t = soup.select('.odd')#